package com.dlwx.parttimetalent.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.dlwx.parttimetalent.R;
import com.dlwx.parttimetalent.bean.DaRenBean;
import com.dlwx.parttimetalent.comm.Constant;
import com.dlwx.parttimetalent.ui.AttentionUser2Activity;
import com.dlwx.parttimetalent.ui.AttentionUserClassifyActivity;
import com.dlwx.parttimetalent.ui.OrderReceActivity;
import com.dlwx.parttimetalent.utils.SPUtils;
import com.dlwx.parttimetalent.utils.StringUtil;

/**
 * Created by Administrator on 2017/11/21.
 */

public class ClassifyDaRenAdapter extends BaseMultiAdapter<DaRenBean.BodyBean> {
    private  Context context;
    private int userId=0;
    private  String labelName1;
    public ClassifyDaRenAdapter(Context context, String labelName) {
        super(context);
        {
            addItemType(DaRenBean.BodyBean.DAREN, R.layout.item_attention);
            addItemType(DaRenBean.BodyBean.DIVER, R.layout.item_diver);
        }
        this.labelName1=labelName;
        this.context=context;
        userId= (int) SPUtils.get(context, Constant.USER_ID,0);
    }

//    @Override
//    public int getLayoutId() {
//        return R.layout.item_attention;
//    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, final int position) {
        final DaRenBean.BodyBean bean = getDataList().get(position);
        if(bean.getType()==DaRenBean.BodyBean.DIVER ){

        }else{
            bindDaren(bean,holder,position);
        }

    }

    private void bindDaren(final DaRenBean.BodyBean bean, SuperViewHolder holder, final int position) {
        ImageView imageHeader=holder.getView(R.id.iamge_header);
        TextView tvName=holder.getView(R.id.tv_name);
        TextView tvStatus=holder.getView(R.id.tv_status);
        TextView tvAddress=holder.getView(R.id.tv_address);
        TextView tv_setting=holder.getView(R.id.tv_setting);
        final TextView tvServer=holder.getView(R.id.tv_server);
        TextView tvGrade=holder.getView(R.id.tv_grade);
        TextView tvPrice=holder.getView(R.id.tv_price);
        TextView tvConfrim=holder.getView(R.id.tv_confirm);
        final RelativeLayout rl_grade=holder.getView(R.id.rl_grade);
        final LinearLayout ll_user_info=holder.getView(R.id.ll_user_info);
        RelativeLayout rl_name=holder.getView(R.id.rl_name);
//        意向
        TextView tvAge=holder.getView(R.id.tv_age);
        ImageView imageAge=holder.getView(R.id.image_age);
        LinearLayout llAge=holder.getView(R.id.ll_age);
        TextView tvHeight=holder.getView(R.id.tv_height);
        TextView tvWeight=holder.getView(R.id.tv_weight);
        TextView tvEducation=holder.getView(R.id.tv_education);
        TextView tvCertificate=holder.getView(R.id.tv_certificate);
        TextView tvAuthname=holder.getView(R.id.tv_authname);
        String remarkName=bean.getRemarkName();
        if(TextUtils.isEmpty(remarkName)){
            tvName.setText(StringUtil.subName(bean.getNickname()));
        }else{
            tvName.setText(StringUtil.subName(remarkName));
        }
        Glide.with(context).load(bean.getHeadurl()).apply(new RequestOptions().error(R.mipmap.logopro).placeholder(R.mipmap.logopro)).into(imageHeader);

        if(userId!=bean.getListid()){
            tv_setting.setVisibility(View.GONE);
        }
        int online=bean.getOnline();
        if(online==1){
            tvStatus.setText("(在线   可接单)");
            tvStatus.setTextColor(ContextCompat.getColor(context,R.color.colorAccent));
        }else{
            tvStatus.setText("(隐身   不可接单)");
            tvStatus.setTextColor(ContextCompat.getColor(context,R.color.third_textcolor));
        }
        tvAddress.setText(bean.getRange());
        String labelName = bean.getLabelname();
        tvServer.setText(labelName1);
        tvGrade.setText(bean.getScore()+"分");
        tvPrice.setText(bean.getPricestart());

        DaRenBean.BodyBean.AgeBean ageBean = bean.getAge();
        if(TextUtils.isEmpty(ageBean.getValue())){
            llAge.setVisibility(View.GONE);
        }else{
            llAge.setVisibility(View.VISIBLE);
            tvAge.setText(ageBean.getValue());
            if(ageBean.getCorlor()==1){
                llAge.setBackgroundColor(ContextCompat.getColor(context,R.color.colorPrimary));
                imageAge.setBackgroundResource(R.mipmap.icon_nansheng);
            }else{
                llAge.setBackgroundColor(ContextCompat.getColor(context,R.color.label_pink));
                imageAge.setBackgroundResource(R.mipmap.icon_nvsheng);
            }
        }
//
        DaRenBean.BodyBean.HeightBean heightBean = bean.getHeight();
        if(TextUtils.isEmpty(heightBean.getValue())){
            tvHeight.setVisibility(View.GONE);
        }else{
            tvHeight.setVisibility(View.VISIBLE);
            tvHeight.setText(heightBean.getValue()+"cm");
        }
//
        DaRenBean.BodyBean.WeightBean weightBeanBean = bean.getWeight();
        if(TextUtils.isEmpty(weightBeanBean.getValue())){
            tvWeight.setVisibility(View.GONE);
        }else{
            tvWeight.setVisibility(View.VISIBLE);
            tvWeight.setText(weightBeanBean.getValue()+"kg");
        }
//
        DaRenBean.BodyBean.EducationBean educationBean = bean.getEducation();
        if(TextUtils.isEmpty(educationBean.getValue())){
            tvEducation.setVisibility(View.GONE);
        }else{
            tvEducation.setVisibility(View.VISIBLE);
            tvEducation.setText(educationBean.getValue());
        }
//
        DaRenBean.BodyBean.AuthnameBean authnameBean = bean.getAuthname();
        if(authnameBean.getCorlor()==66){
            tvAuthname.setVisibility(View.GONE);
        }else{
            tvAuthname.setVisibility(View.VISIBLE);
//            tvAuthname.setText(authnameBean.getValue());
        }
        imageHeader.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i=new Intent(context, AttentionUser2Activity.class);
                i.putExtra("listId",bean.getListid()+"");
                context.startActivity(i);
            }
        });
        if(position!=0){
            final Intent i = new Intent(context, AttentionUserClassifyActivity.class);
            i.putExtra("listId", bean.getListid() + "");
            rl_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                        context.startActivity(i);

                }
            });
            ll_user_info.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                        context.startActivity(i);

                }
            });
            tvServer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                        context.startActivity(i);

                }
            });
            rl_grade.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                        context.startActivity(i);
                }
            });
        }else{
            rl_name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    if(position==0){
                        context.startActivity(new Intent(context, OrderReceActivity.class));
//                    }
                }
            });
            ll_user_info.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    if(position==0){
                        context.startActivity(new Intent(context, OrderReceActivity.class));
//                    }
                }
            });
            tvServer.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    if(position==0){
                        Intent i=new Intent(context, AttentionUserClassifyActivity.class);
                        i.putExtra("listId", bean.getListid()+"");
                        context.startActivity(i);
//                    }
                }
            });
            rl_grade.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent i=new Intent(context, AttentionUserClassifyActivity.class);
                    i.putExtra("listId", bean.getListid()+"");
                    context.startActivity(i);
                }
            });
        }

    }
}
